package com.wl.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.wl.dao.Delivery_07Mapper;
import com.wl.dao.LoginfoMapper;
import com.wl.entity.Delivery_07;
import com.wl.entity.Loginfo;
import com.wl.service.Delivery_07Service;
import com.wl.util.PageData;

/**
 * 业务层实现类
 * 
 * @author HCH
 *
 */
@Service
public class Delivery_07ServiceImpl implements Delivery_07Service {

	// 注入一个Delivery_07Mapper
	@Autowired
	private Delivery_07Mapper deliveryMapper;

	@Autowired
	private LoginfoMapper loginMapper;
	/**
	 * 动态sql语句添加业务信息
	 */
	@Override
	public boolean insertSelective(Delivery_07 record) {
		// TODO Auto-generated method stub
		int n = deliveryMapper.insertSelective(record);
		if (n > 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 根据当前处理人编号查找尚未处理的业务并分页
	 */
	@Override
	public PageData<Delivery_07> selectDeliveryByDeliveryno(int page, int limit, String deliveryno) {
		// TODO Auto-generated method stub
		// 设置起始位置
		int start = 0;
		if (page >= 1) {
			start = (page - 1) * limit;
		}
		// 查询总页数
		int totalCount = deliveryMapper.selectDeliveryByDeliverynoCount(deliveryno);
		// 分页的数据
		List<Delivery_07> data = deliveryMapper.selectDeliveryByDeliveryno(start, limit, deliveryno);
		// 构造方法：赋值内容为 数据、总记录数、limit、page
		PageData<Delivery_07> pageData = new PageData<Delivery_07>(data, totalCount, limit, page);
		// code、Msg，前端layui所需要的参数
		pageData.setCode(0);
		pageData.setMsg("");

		return pageData;
	}

	/**
	 * 根据flowid动态修改
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
	public boolean updateByPrimaryKeySelective(Delivery_07 delivery,Loginfo log) {
		// TODO Auto-generated method stub
		int n =deliveryMapper.updateByPrimaryKeySelective(delivery);
		int m =loginMapper.insert(log);
		if(n>0&&m>0) {
			return true;
		}else {
			return false;
		}	
	}

	/**
	 * 查询已审批的数量，页面显示数据用
	 */
	@Override
	public int getCountByDelivery() {
		// TODO Auto-generated method stub
		return deliveryMapper.getCountByDelivery();
	}
}
